package com.zfsoft.test.tool;

import java.awt.*;
import java.awt.datatransfer.StringSelection;
import java.awt.event.KeyEvent;

public class Common {
    public static void uploadFile(String filePath){
        // 新建一个Robot类的对象
        try {

            // 指定图片的路径，这里我放桌面上
            StringSelection sel = new StringSelection(filePath);
            // 把图片文件路径复制到剪贴板
            Toolkit.getDefaultToolkit().getSystemClipboard().setContents(sel,null);

            Robot robot = new Robot();
            Thread.sleep(1000);

            // 按下回车
            robot.keyPress(KeyEvent.VK_ENTER);

            // 释放回车
            robot.keyRelease(KeyEvent.VK_ENTER);

            // 按下 CTRL+V
            robot.keyPress(KeyEvent.VK_CONTROL);
            robot.keyPress(KeyEvent.VK_V);

            // 释放 CTRL+V
            robot.keyRelease(KeyEvent.VK_CONTROL);
            robot.keyRelease(KeyEvent.VK_V);
            Thread.sleep(1000);

            // 点击回车 Enter
            robot.keyPress(KeyEvent.VK_ENTER);
            robot.keyRelease(KeyEvent.VK_ENTER);
        } catch (AWTException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
